let git_config = git_config.as_ref();
let name = git_config.and_then(|g| g.get_str("user.name").ok())
.map(|s| s.to_string())
- .or_else(|| os::getenv("USER"));
+ .or_else(|| os::getenv("USER")) // unix
+ .or_else(|| os::getenv("USERNAME")); // windows
let name = match name {
Some(name) => name,
- None => return Err(human("could not determine the current user, \
- please set $USER"))
+ None => {
+ let username_var = if cfg!(windows) {"USERNAME"} else {"USER"};
+ return Err(human(format!("could not determine the current \
+ user, please set ${}", username_var)))
+ }
};
let email = git_config.and_then(|g| g.get_str("user.email").ok());
assert!(toml.as_slice().contains(r#"authors = ["foo"]"#));
})
+test!(finds_author_username {
+ // Use a temp dir to make sure we don't pick up .cargo/config somewhere in
+ // the hierarchy
+ let td = TempDir::new("cargo").unwrap();
+ assert_that(cargo_process("new").arg("foo")
+ .env("USER", None::<&str>)
+ .env("USERNAME", Some("foo"))
+ .cwd(td.path().clone()),
+ execs().with_status(0));
+
+ let toml = td.path().join("foo/Cargo.toml");
+ let toml = File::open(&toml).read_to_string().assert();
+ assert!(toml.as_slice().contains(r#"authors = ["foo"]"#));
+})
+
test!(finds_author_git {
my_process("git").args(["config", "--global", "user.name", "bar"])
.exec().assert();